import {defineStore} from "pinia";
//自定义选项卡数据类型
export type Tab = {
    title: string,
    path: string,
}
//自定义state数据类型
export type TabState = {
    tabList: Tab[]
}
//这个store用于tab选项卡的数据
export const useTabStore = defineStore('myTabStore', {
    state: (): TabState => {
        return {
            tabList: [],
        }
    },
    getters: {
        getTabs(state) {
            return state.tabList
        }
    },
    actions: {
        //添加选项卡
        addTab(tab: Tab) {
            //判官选项卡是否已经存在
            if (this.tabList.some(item => item.path == tab.path)) return
            if (tab.path == '/dashboard') {
                //如果是首页加到第一个
                this.tabList.unshift(tab)
            } else {
                this.tabList.push(tab)
            }
        }
    },
    persist: {
        storage: sessionStorage
    }
})